package com.qf.simpleTrigger;

import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * IntelliJ IDEA -> springboot120622
 * 2019/12/7 8:25
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
//简单触发器
@Component
public class SimpleTriggerUtil  {

    @Autowired
    @Qualifier("getsch")
    private Scheduler scheduler;

    //实现任务绑定
    @PostConstruct
    public  void beginSimple(){
        try {
            JobDetail jobDetail = JobBuilder.newJob(MySimpleJob.class).withIdentity("jobaa").build();
            SimpleScheduleBuilder builder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever();
            SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().withIdentity("mytrigger").withSchedule(builder).build();
            scheduler.scheduleJob(jobDetail,simpleTrigger);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
